import {api} from './libs/api.js';
import {member} from '@/api/member.js';

import {getSystemInfo,wxqyLogin,getSessionCode2} from '@/common/wechat.js';

let _self;
export const index =  {
	data() {
		return {
			optLock:false,
			scrollTop: 0,
			old: {
				scrollTop: 0
			},
			productList:[],
			articleList:[]
		}
	},
	
	mounted() {
		_self = this;
	},
	
	methods: {

		async initData(){
			let userToken =  uni.getStorageSync('USER_TOKEN');
			if(userToken){
				let retInfo = await member.heartBeat({});
				if(retInfo["overtime"]=="true"){
					uni.reLaunch({url:"/packagePages1/pages/presets/index"});
					return true;
				}
			}
			
			
			let productInfo=await api.productList({});
			let articleInfo=await api.articleList({});
			
			if(productInfo) this.productList=productInfo["dataList"];
			if(articleInfo) this.articleList=articleInfo["dataList"];
			
			/*wx.qy.checkSession({
				success: function(){
					console.log("111");
					//session_key 未过期，并且在本生命周期一直有效
				},
				fail: function(){
					console.log("222");
					// session_key 已经失效，需要重新执行登录流程
					wx.qy.login() //重新登录
				}
			})
			console.log("666");
			
			wx.qy.getEnterpriseUserInfo ({
				success: function(res) {
					var userInfo = res.userInfo
					var name = userInfo.name
					var gender = userInfo.gender //性别 0：未知、1：男、2：女
					console.log(res);
				}
			})*/
			
			/*let systemInfo = await getSystemInfo({});//获取系统信息
			if(systemInfo.environment=="wxwork"){
				let loginInfo = await wxqyLogin({});
				if(loginInfo["code"]){
					let userInfo= await getSessionCode2({code:loginInfo.code});
					console.log(loginInfo);
					
					let userToken =  uni.getStorageSync('USER_TOKEN');
					
				}
			}*/
			/*wx.qy.login({
				success: function(res) {
					if (res.code) {
					  //发起网络请求
					 
					 console.log(res);
					} else {
					  console.log('登录失败！' + res.errMsg)
					}
				}
			});*/
		
			
		},
		upper: function(e) {
			console.log(e)
		},
		lower: function(e) {
			console.log(e)
		},
		scroll: function(e) {
			console.log(e)
			this.old.scrollTop = e.detail.scrollTop
		},
		goTop: function(e) {
			// 解决view层不同步的问题
			this.scrollTop = this.old.scrollTop
			this.$nextTick(function() {
				this.scrollTop = 0
			});
			uni.showToast({
				icon: "none",
				title: "纵向滚动 scrollTop 值已被修改为 0"
			})
		}
				
	},
}